package com.example.controller.siyunDingdanController;

import com.example.pojo.siyunDingdanPojo.SiyunDingdan;
import com.example.pojo.siyunDingdanPojo.SiyunPoi;
import com.example.pojo.siyunDingdanPojo.SiyunTuihuo;
import com.example.pojo.siyunDingdanPojo.SiyunTuihuoStatus;
import com.example.service.siyunDingdanService.SiyunTuihuoDingdanService;
import com.github.stupdit1t.excel.common.PoiWorkbookType;
import com.github.stupdit1t.excel.core.ExcelHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @ClassName: ***
 * @Description: ***
 * @author: ***
 * @date: 2022/11/28 16:23
 */
@RestController
@CrossOrigin
public class SiyunTuihuoDingdanController {
    @Autowired
    private SiyunTuihuoDingdanService siyunTuihuoDingdanService;
    /**
    * @Author: lzr
    * @Description: 首先获得处于退货状态的各个状态的数量
    * @DateTime: 16:23 2022/11/28
    * @Params: 
    * @Return 
    */
    @PostMapping("/GetTuihuoStatus")
    public SiyunTuihuoStatus getTuihuoStatus(){
        return siyunTuihuoDingdanService.getTuihuoStatus();
    }
    
    /**
    * @Author: lzr
    * @Description: 此方法用来获取全部数据然后渲染到表格中
    * @DateTime: 19:02 2022/11/28
    * @Params: 
    * @Return 
    */
    @PostMapping("/getTuihuoDingdan")
    public List<SiyunDingdan> getTuihuoDingdan(@RequestBody SiyunDingdan siyunDingdan){
        return siyunTuihuoDingdanService.getTuihuoDingdanAll(siyunDingdan);
    }
    
    /**
    * @Author: lzr
    * @Description: 退货订单模糊查
    * @DateTime: 20:30 2022/11/28
    * @Params: 
    * @Return 
    */
    @PostMapping("/getTuihuoMohucha")
    public List<SiyunDingdan> getTuihuoDingdanMohucha(@RequestBody SiyunDingdan siyunDingdan){
        return siyunTuihuoDingdanService.getTuihuoMohuCha(siyunDingdan);
    }
    /**
    * @Author: lzr
    * @Description: 导出退货信息
    * @DateTime: 13:49 2022/11/29
    * @Params:
    * @Return
    */
    @RequestMapping("/getExcel")
    @ResponseBody
    public boolean getExcel(@RequestBody SiyunPoi siyunPoi){
        boolean key = true;
        // 1.获取列表数据
        String shopId = siyunPoi.getShopId();
        String[] split = shopId.split(",");
        List<Integer> list = new ArrayList<>();
        for (String s : split) {
            Integer it=Integer.valueOf(s);
            list.add(it);
        }
        List<SiyunDingdan> excel = siyunTuihuoDingdanService.getExcel(list);
        // 2.执行导出
        ExcelHelper.opsExport(PoiWorkbookType.XLSX)
                .opsSheet(excel)
                .opsHeader().simple()
                .texts("订单编号", "申请时间", "用户账号", "退款金额","联系人","联系电话","申请状态","处理时间").done()
                .opsColumn()
                .fields("shopId","updateDate","account","logisticsFee","nickname","phone","orderStatus","chuliDate").done()
                .done().export("D://测试/a.xlsx");
        return key;
    }

    /**
    * @Author: lzr
    * @Description: 查看退回申请订单的详情
    * @DateTime: 13:48 2022/12/2
    * @Params:
    * @Return
    */
    @PostMapping("/getTuihuoZhong")
    public SiyunTuihuo getTuihuoZhong(@RequestBody SiyunTuihuo siyunTuihuo){
        return siyunTuihuoDingdanService.getTuihuoZhong(siyunTuihuo);
    }

    /**
    * @Author: lzr
    * @Description: 确认收货
    * @DateTime: 9:53 2022/12/5
    * @Params:
    * @Return
    */
    @PostMapping("/getQueren")
    public boolean getQuerenshouhuo(@RequestBody SiyunTuihuo siyunTuihuo){
        Date date = new Date();
        SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = sdf.format(date);
        siyunTuihuo.setChuliDate(format);
        return siyunTuihuoDingdanService.getQuerenshouhuo(siyunTuihuo);
    }
    /**
    * @Author: lzr
    * @Description: 确认收货 拒绝收货
    * @DateTime: 10:27 2022/12/6
    * @Params:
    * @Return
    */
    @PostMapping("/getReturn")
    public boolean getReturn(@RequestBody SiyunTuihuo siyunTuihuo){
        Date date = new Date();
        SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = sdf.format(date);
        siyunTuihuo.setChuliDate(format);
        return siyunTuihuoDingdanService.getReturn(siyunTuihuo);
    }
}
